layui.use(['table', 'admin', 'form', 'ax', 'upload','layer','laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var form = layui.form;
    var upload = layui.upload;
    var layer = layui.layer;
    var laydate = layui.laydate;
    /**
     * 门店装修表管理
     */
    var Mdzx = {
        tableId: "mdzxdzTable"
    };
    //渲染时间选择框
    laydate.render({
        elem: '#zdrq',
        trigger: 'click',
        // max: Feng.currentDate()
    });

    form.on('select(status)', function (data) {
        Mdzx.search();
    });

    form.on('select(yuSuanLockMdzx)', function (data) {
        Mdzx.search();
    });

    /**
     * 初始化表格的列
     */
    Mdzx.initColumn = function () {
        return [[
            //{type: 'checkbox'},
            {type: 'numbers', title: '序号', align: "center", width: 45},
            //{field: 'btyZxMdzxId', hide: true, title: '主键'},
            // {field: 'btyBrandId', sort: true, title: '门店id'},
            {field: 'btyBrandIdView', align: "left", title: '门店名称', width: 300},
            //{field: 'mdBianma', align: "center", title: '妖码', width: 90},
            {
                field: 'yujiTouzi',
                title: '总投资',
                align: "center",
                width: 130,
                templet: function (row) {
                    if (row.yujiTouzi == null || row.yujiTouzi == '') {
                        return "0";
                    } else {
                        return row.yujiTouzi;
                    }
                }
            },
            {
                field: 'touzishengyu',
                title: '投资剩余',
                align: "center",
                width: 130,
                templet: function (row) {
                    if (row.touzishengyu == null || row.touzishengyu == '') {
                        return "0";
                    } else {
                        return row.touzishengyu;
                    }
                }
            },
             {field: 'statusName',title: '状态', width: 100},
             {field: 'jine',title: '金额'},
            // {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 350},
            // {field: 'createUserName', title: '创建人', width: 80, align: "center",},
            // {field: 'createTime', title: '创建时间', align: "center",width: 170}

        ]];
    };

    /**
     * 点击查询按钮
     */
    Mdzx.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['lock'] = $("#yuSuanLockMdzx").val();
        queryData['status'] = $("#status").val();
        table.reload(Mdzx.tableId, {where: queryData});
    };

    /**
     * 导出excel按钮
     */
    Mdzx.exportExcel = function () {
        // var checkRows = table.checkStatus(Mdzx.tableId);
        // if (checkRows.data.length === 0) {
        //     Feng.error("请选择要导出的数据");
        // } else {
        //     table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        // }
        //获取导出Excel的数据
        var ajax = new $ax(Feng.ctxPath + "/mdzx/listSearchExport");
        var condition = $("#condition").val();
        var status = $("#status").val();
        ajax.set("condition", condition);
        ajax.set("status", status);
        var result = ajax.start();
        table.exportFile(tableResult.config.id, result, 'xls');
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Mdzx.tableId,
        url: Feng.ctxPath + '/mdzx/listDz',
        page: true,
        height: "full-59",
        cellMinWidth: 100,
        limit:20,
        totalRow: true,
        cols: Mdzx.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Mdzx.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        Mdzx.exportExcel();
    });

    //监听行单击事件（双击事件为：rowDouble）
    table.on('row(mdzxdzTable)', function(obj){
        var data = obj.data;

        $('div[lay-id="mdzxdzTable"]').find(".layui-table-body tr ").attr({ "style": "background:#FFFFFF" });//其他tr恢复原样

        $('div[lay-id="mdzxdzTable"]').find(obj.tr.selector).attr({ "style": "background:#C0C0C0" });//改变当前tr颜色
        var btyZxMdzxId = data.btyZxMdzxId;

    });
});
